package diploma.kisel.modelas.service;

import java.util.List;

import diploma.kisel.modelas.domain.Concept;
import diploma.kisel.modelas.domain.Project;
import diploma.kisel.modelas.repository.ConceptRepositoryImpl;
import diploma.kisel.modelas.repository.api.ConceptRepository;
import diploma.kisel.modelas.service.api.ConceptService;

public class ConceptServiceImpl implements ConceptService {

	private ConceptRepository conceptRepository = new ConceptRepositoryImpl();

	@Override
	public List<Concept> findAll() {
		return conceptRepository.findAll();
	}

	@Override
	public Concept findById(int id) {
		if (id >= 0)
			return conceptRepository.findById(id);
		else
			return null;
	}

	@Override
	public Concept save(Concept concept) {
		if (concept.getId() != null)
			return conceptRepository.update(concept);
		else
			return conceptRepository.save(concept);
	}

	@Override
	public void remove(Concept concept) {
		if (concept != null && concept.getId() != null)
			conceptRepository.remove(concept);

	}

	@Override
	public void remove(int id) {
		Concept concept = findById(id);
		remove(concept);
	}

	@Override
	public List<Concept> findByProject(Project project) {
		return conceptRepository.findByProject(project);
	}

}
